<template>
<!-- 活动审核 -->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="120px">
      <el-form-item label="邀请人手机号" prop="inviteMobile">
        <el-input
          v-model="queryParams.inviteMobile"
          placeholder="请输入邀请人手机号"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邀请时间">
        <el-date-picker
          v-model="yqTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select style="width: 240px" v-model="queryParams.status" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in activitiesTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="被邀请人手机号" prop="userMobile">
        <el-input
          v-model="queryParams.userMobile"
          placeholder="请输入被邀请人手机号"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" border :data="getActivitiesDetails">
      <el-table-column label="审核编号" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.id | showTxt }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动名称" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.sourceCode=='InviteFriends'">邀请好友</span>
          <span v-if="scope.row.sourceCode=='newUserExperience'">新用户体验</span>
        </template>
      </el-table-column>
      <el-table-column label="被邀请人昵称" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.userNickName | showTxt }}</span>
        </template>
      </el-table-column>
      <el-table-column label="被邀请人手机号" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.userMobile | showTxt }}</span>
        </template>
      </el-table-column>
      <el-table-column label="邀请人昵称" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.inviteNickName | showTxt }}</span>
        </template>
      </el-table-column>
      <el-table-column label="邀请人手机号" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.inviteMobile | showTxt }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动金额/元" width="100" prop="num">
        <template slot-scope="scope">
          <span>{{ scope.row.rewardAmount | rounding }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核资料" width="150">
        <template slot-scope="scope">
          <div v-if="scope.row.fileId==undefined || scope.row.fileId== '' || scope.row.fileId ==null">
            <span>暂无图片资料</span>
          </div>
          <div v-else-if="scope.row.fileId !==undefined || scope.row.fileId !== '' || scope.row.fileId !==null">
            <el-popover
              placement="left"
              title=""
              trigger="hover">
              <el-image slot="reference" :src="scope.row.fileId" :alt="scope.row.fileId" style="max-height: 70px;max-width: 100px"></el-image>
              <el-image :src="scope.row.fileId" style="height: 500px;width: 500px"></el-image>
            </el-popover>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.status==0">待领取</span>
          <span v-if="scope.row.status==1">已完成</span>
          <span v-if="scope.row.status==2">待审核</span>
          <span v-if="scope.row.status==3">已驳回</span>
          <span v-if="scope.row.status==4">已作废</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status == 2"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['reviewActivities:activities:edit']"
          >通过</el-button>
          <el-button
            v-if="scope.row.status == 0 || scope.row.status == 2"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['reviewActivities:activities:remove']"
          >作废</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { listActivities,passAudit,invalidAudit, exportPost } from "@/api/reviewActivities/activitiesDetail";
  export default {
    name: "Activities",
    data() {
      return {
        loading: false,
        // 总条数
        total: 0,
        // 邀请时间范围
        yqTime: [],
        // 审核状态数据字典
        activitiesTypeOptions: [],
        // 明细列表
        getActivitiesDetails: [],
        // 查询参数
        queryParams: {
          page: 1,
          pageSize: 10,
          id:undefined, //审核编号
          sourceCode:undefined,//活动名称
          userNickName:undefined,//被邀请人名称
          userMobile:undefined,//被邀请人手机号
          inviteNickName:undefined, //邀请人昵称
          inviteMobile:undefined,//邀请人手机号
          fileId:undefined, //审核资料
          status:undefined,  //审核状态
          rewardAmount:undefined//活动金额
        }
      };
    },
    filters: {
      showTxt(txt) {
        return txt ? txt : '--'
      },
      rounding (value) {
        return value.toFixed(2)
      }
    },
    created() {
      this.getStatus();
      this.getList();
    },
    methods: {
     //审核状态
      getStatus() {
        this.activitiesTypeOptions=[{'dictValue':'0','dictLabel':'待领取'},{'dictValue':'1','dictLabel':'已完成'},{'dictValue':'2','dictLabel':'待审核'},{'dictValue':'4','dictLabel':'已作废'}];
      },
      setValueNull() {
        this.queryParams.status=null;
      },
     //查询活动审核列表
      getList(){
        this.loading = true;
        if(this.yqTime.length) {
          this.addCouponDateRange('yqTime', this.queryParams, this.yqTime)
        }
        listActivities(this.queryParams).then(
          response => {
            this.getActivitiesDetails = response.data.content.rows;
            this.total = response.data.content.records;
            this.loading = false;
          }
        );
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      //重置按钮操作
      resetQuery(){
        this.yqTime = [];
        if(this.yqTime.length) {
          this.addCouponDateRange('yqTime', this.queryParams, this.yqTime)
        }
        this.resetForm("queryForm");
        this.handleQuery();
      },
      //通过按钮
      handleUpdate(row) {
        const user_id = row.user_id;
        passAudit(user_id).then(response => {
         if(response.data.isSuccess){
           this.$message('审批通过');
           this.handleQuery();
         }else{
           this.$message('审批失败！请联系管理员');
         }
        });
      },
      //作废按钮
      handleDelete(row){
        const user_id = row.user_id;
        const sourceCode=row.sourceCode;
        invalidAudit(user_id,sourceCode).then(response => {
          if(response.data.isSuccess){
            this.$message('作废通过');
            this.handleQuery();
          }else{
            this.$message('作废失败！请联系管理员');
          }
        });
      },
    }
  };
</script>
